﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Runtime.Serialization;

namespace Toybox.NicoSharp.Live.LiveGuide
{
	using Extensions;
	using Logger;
	using Utilities;

	/// <summary>
	/// 番組状態モード
	/// </summary>
	public enum GetStreamMode
	{
		/// <summary>
		/// 未放送
		/// </summary>
		comingsoon,

		/// <summary>
		/// 終了
		/// </summary>
		closed,
	}

	/// <summary>
	/// ZeroStreamList クラス
	/// </summary>
	[DataContract]
	public partial class ZeroStreamList
	{

		#region [Static]

		/// <summary>
		/// ZeroStreamList 取得
		/// </summary>
		/// <param name="mode"></param>
		/// <param name="page"></param>
		/// <param name="cookies"></param>
		/// <returns></returns>
		public static ZeroStreamList Get(GetStreamMode mode, int page, CookieCollection cookies = null)
		{
			Dictionary<string, string> dict = new Dictionary<string, string>();
			dict.Add("status", Enum.GetName(mode.GetType(), mode));
			dict.Add("zpage", page.ToString());

			string url = NicoUrls.LiveApi + "getindexzerostreamlist?" + Serializer.AndEqualPairSerializer(dict);
			try
			{
				string html = NicoWebClient.Get(url, cookies.Coerce());
				return Deserializer.JsonDeserializer<ZeroStreamList>(html);
			}
			catch (Exception ex)
			{
				TraceLogger.WriteLine(ex.ToString());
				return null;
			}
		}

		#endregion [Static]


		#region Public Members

		/// <summary>
		/// 番組リスト
		/// </summary>
		[DataMember]
		public ZeroStream[] reserved_stream_list;

		/// <summary>
		/// ページ数
		/// </summary>
		[DataMember]
		public int total;

		#endregion Public Members

	}
}
